﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Animation;
using WPF数据采集系统.Base;
using WPF数据采集系统.Model;
using Control = System.Windows.Forms.Control;

namespace WPF数据采集系统.View
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : System.Windows.Controls.UserControl
    {

        public MainView()
        {
            InitializeComponent();
        }

        private void btn_connect_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            PlcStateMonitor psm = new PlcStateMonitor();
            if (MainWindow.mvm.PlcState)
            {
                if (CustomMsgBox.ShowDialog("Warning", "正在与PLC通讯中,是否确认要断开连接?(In communication with PLC, are you sure you want to disconnect?)", CustomMsgBoxButton.Two, CustomMsgBoxImage.Alert).IsYes)
                {
                    MainWindow.mvm.PlcState = false;
                    PlcStateMonitor.PlcContent = "Error";
                    ListBoxHelper.listBoxAdd(MainWindow.mvm.logListBox, "用户:" + MainWindow.LoginUser + "断开了PLC连接", true);
                }
            }
            else
            {
                MainWindow.mvm.PlcState = true;
                MainWindow.mvm.MonitorList.Clear();
                psm.MainRun(MainWindow.mvm.PlcState);
                ListBoxHelper.listBoxAdd(MainWindow.mvm.logListBox, "用户:" + MainWindow.LoginUser + "点击了PLC页面的连接按钮", true);
            }
        }
        
        private void Button_Click(object sender, System.Windows.RoutedEventArgs es)
        {
            this.Height = SystemParameters.WorkArea.Height;
            this.Width = SystemParameters.WorkArea.Width;////得到屏幕工作区域宽度

        } 
    }
}
